/* -------------------------------------------------------------------------- *
   TestWinUnit - Maria Blees (maria.blees@microsoft.com)

   File: TestablePlainTextLogger.cpp
 * -------------------------------------------------------------------------- */
#include "TestablePlainTextLogger.h"

#include <stdio.h>
#include <string.h>
#include <windows.h> // ARRAYSIZE

using namespace WinUnitLib;

TestablePlainTextLogger::TestablePlainTextLogger()
{
    ClearBuffer();
}

PlainTextLogger& TestablePlainTextLogger::operator<<(const wchar_t* str)
{
    char buffer[128] = "";
    _snprintf_s(buffer, ARRAYSIZE(buffer), _TRUNCATE, "%S", str);
    strncat_s(_buffer, ARRAYSIZE(_buffer), buffer, _TRUNCATE);
    return *this;
}

PlainTextLogger& TestablePlainTextLogger::operator<<(const char* str)
{
    char buffer[128] = "";
    _snprintf_s(buffer, ARRAYSIZE(buffer), _TRUNCATE, "%s", str);
    strncat_s(_buffer, ARRAYSIZE(_buffer), buffer, _TRUNCATE);
    return *this;
}

PlainTextLogger& TestablePlainTextLogger::operator<<(unsigned int i)
{
    char buffer[128] = "";
    _snprintf_s(buffer, ARRAYSIZE(buffer), _TRUNCATE, "%u", i);
    strncat_s(_buffer, ARRAYSIZE(_buffer), buffer, _TRUNCATE);
    return *this;
}

void TestablePlainTextLogger::ClearBuffer()
{
    ZeroMemory((void*)_buffer, ARRAYSIZE(_buffer)*sizeof(_buffer[0]));
}

char* TestablePlainTextLogger::GetBuffer()
{
    return _buffer;
}
